import ctypes
import threading
import time

import win32con
from PyQt5.QtCore import QThread

i = 0
class My_ThreadTest(QThread):
    def run(self):
        try:
        	# 这个目前我没弄明白这里写法
            self.handle = ctypes.windll.kernel32.OpenThread(  # @UndefinedVariable
                win32con.PROCESS_ALL_ACCESS, False, int(QThread.currentThreadId()))
            print("成功")
        except Exception as e:
            print('get thread handle failed', e)
        print('thread id', int(QThread.currentThreadId()))

        global i
        while True:
            print(i)
            i += 1
            time.sleep(1)


if __name__ == '__main__':
    _thread = My_ThreadTest()
    _thread.start()
    _thread1 = My_ThreadTest()
    time.sleep(5)
    _thread1.start()

    print('main id', int(QThread.currentThreadId()))


    time.sleep((10))
    ret = ctypes.windll.kernel32.TerminateThread(  # @UndefinedVariable
        _thread.handle, 0)
    print('终止线程', _thread.handle, ret)
    # time.sleep(5)

    # My_ThreadTest()
    # print(i)